home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / WANDR401.ZIP / sources / FALL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-31  |  9.9 KB  |  336 lines

  1. /*       fall.c                                  */
  2.  
  3. /*    Animates falling boulders and moving       */
  4. /*    arrows.                                    */
  5.  
  6.  
  7.  
  8. #include "wand_head.h"
  9. //#include <allegro.h>
  10. #include "samples.h"
  11.  
  12. extern char lscreen[NOOFROWS][ROWLEN+1];
  13. extern int pause1;
  14. extern int recording;
  15. extern int audio_flag;
  16.  
  17. int moving = 0;    /* so that bombs explode only if something *hits* them */
  18.  
  19. int check(mx, my, x, y, dx, dy, sx, sy, howdead)
  20. /* check for any falling caused by something moving out of x,y along
  21.    vector dx,dy. All the others are constant and should really have
  22.    been global...                             */
  23. int x, y, sx, sy, dx, dy, *mx, *my;
  24. char howdead[25];
  25. {
  26.     int ret = 0;
  27.     /* if(recording != 2) flushinp();  type ahead gets in the way */
  28.     ret += fall(mx,my,x,y,sx,sy,howdead);
  29.     ret += fall(mx,my,x-dx,y-dy,sx,sy,howdead);
  30.     ret += fall(mx,my,x-dy,y-dx,sx,sy,howdead);
  31.     ret += fall(mx,my,x+dy,y+dx,sx,sy,howdead);
  32.     ret += fall(mx,my,x-dx-dy,y-dy-dx,sx,sy,howdead);
  33.     ret += fall(mx,my,x-dx+dy,y-dy+dx,sx,sy,howdead);
  34.     return ret;
  35. }
  36.  
  37. int fall(mx, my, x, y, sx, sy, howdead)
  38. /* recursive function for falling */
  39. /* boulders and arrows */
  40. int  x, y, sx, sy, *mx, *my;
  41. char howdead[25];
  42. {
  43.     int nx = x, nxu = x, nyl = y, nyr = y, ny = y, retval = 0;
  44.     if ((y > (NOOFROWS-1)) || (y < 0) || (x < 0) || (x > (ROWLEN-1)))
  45.     return(0);
  46.     if (lscreen[y][x] == '~') {
  47.     if (lscreen[y-1][x] == ' ') fall(mx,my,x,y-1,sx,sy,howdead);
  48.     if (lscreen[y+1][x] == ' ') fall(mx,my,x,y+1,sx,sy,howdead);
  49.     if (lscreen[y][x-1] == ' ') fall(mx,my,x-1,y,sx,sy,howdead);
  50.     if (lscreen[y][x+1] == ' ') fall(mx,my,x+1,y,sx,sy,howdead);
  51.     }
  52.     if ((lscreen[y][x] != 'O') && (lscreen[y][x] != ' ') &&
  53.     (lscreen[y][x] != 'M') && (lscreen[y][x] !='\\') &&
  54.     (lscreen[y][x] != '/') && (lscreen[y][x] != '@') &&
  55.     (lscreen[y][x] != '^') && (lscreen[y][x] != 'B'))
  56.     return(0);
  57.     if ((lscreen[y][x] == 'B') && (moving == 0))
  58.     return 0;
  59.     if (lscreen[y][x] == 'O') {
  60.     if ((lscreen[y][x-1] == ' ') && (lscreen[y-1][x-1] == ' '))
  61.         nx--;
  62.     else {
  63.         if ((lscreen[y][x+1] == ' ') && (lscreen[y-1][x+1] == ' '))
  64.         nx++;
  65.         else
  66.         nx = -1;
  67.     }
  68.     if ((lscreen[y][x-1] == ' ') && (lscreen[y+1][x-1] == ' '))
  69.         nxu--;
  70.     else {
  71.         if ((lscreen[y][x+1] == ' ') && (lscreen[y+1][x+1] == ' '))
  72.         nxu++;
  73.         else
  74.         nxu = -1;
  75.     }
  76.     if ((lscreen[y-1][x] == ' ') && (lscreen[y-1][x+1] == ' '))
  77.         nyr--;
  78.     else {
  79.         if ((lscreen[y+1][x] == ' ') && (lscreen[y+1][x+1] == ' '))
  80.         nyr++;
  81.         else
  82.         nyr = -1;
  83.     }
  84.     if ((lscreen[y-1][x] == ' ') && (lscreen[y-1][x-1] == ' '))
  85.         nyl--;
  86.     else {
  87.         if ((lscreen[y+1][x] == ' ') && (lscreen[y+1][x-1] == ' '))
  88.         nyl++;
  89.         else
  90.         nyl = -1;
  91.     }
  92.     }
  93.     if (lscreen[y][x] == '\\') {
  94.     if (lscreen[y-1][++nx] != ' ')
  95.         nx = -1;
  96.     if (lscreen[y+1][--nxu] != ' ')
  97.         nxu = -1;
  98.     if (lscreen[--nyr][x+1] != ' ')
  99.         nyr = -1;
  100.     if (lscreen[++nyl][x-1] != ' ')
  101.         nyl = -1;
  102.     }
  103.     if (lscreen[y][x] == '/') {
  104.     if (lscreen[y-1][--nx] != ' ')
  105.         nx = -1;
  106.     if (lscreen[y+1][++nxu] != ' ')
  107.         nxu = -1;
  108.     if (lscreen[++nyr][x+1] != ' ')
  109.         nyr = -1;
  110.     if (lscreen[--nyl][x-1] != ' ')
  111.         nyl = -1;
  112.     }
  113.     if ((lscreen[y][nx] != ' ') && (lscreen[y][nx] != 'M') &&
  114.     (lscreen[y][nx] != 'B'))
  115.     nx = -1;
  116.     if ((lscreen[y-1][x] == 'O') && (nx >= 0) && (y > 0)) { /* boulder falls ? */
  117.     moving = 1;
  118.     lscreen[y-1][x] = ' ';
  119.     if (lscreen[y][nx] == '@') {
  120.         strcpy(howdead,"a falling boulder");
  121.             if(audio_flag) play_audio_sample(KILLED_BY_O_SND);
  122.         retval = 1;
  123.     }
  124.     if (lscreen[y][nx] == 'M') {
  125.         *mx = *my = -2;
  126.         lscreen[y][nx] = ' ';
  127.             if(audio_flag) play_audio_sample(DEAD_M_SND);
  128.     }
  129.     if (lscreen[y][nx] == 'B') {
  130.         retval = bang(nx,y,mx,my,sx,sy,howdead);
  131.         return retval;
  132.     }
  133.     lscreen[y][nx] = 'O';
  134.  
  135.         draw_object(y-1,x,' ');
  136.     draw_object(y,nx,'O');
  137.         if(audio_flag) play_audio_sample(MOVING_BOULDER_SND);
  138.         refresh_screen();
  139.     delay(pause1);
  140.     retval += fall(mx,my,nx ,y+1,sx,sy,howdead);
  141.     moving = 0;
  142.     retval += check(mx,my,x,y-1,0,1,sx,sy,howdead);
  143.     if (y + 1 < NOOFROWS && lscreen[y+1][nx] == '@') {
  144.         strcpy(howdead,"a falling boulder");
  145.             if(audio_flag) play_audio_sample(KILLED_BY_O_SND);
  146.         return(1);
  147.         }
  148.     if (y + 1 < NOOFROWS && lscreen[y+1][nx] == 'M') {
  149.         *mx = *my = -2;
  150.         lscreen[y+1][nx] = ' ';
  151.             if(audio_flag) play_audio_sample(DEAD_M_SND);
  152.     }
  153.     }
  154.     if ((lscreen[nyr][x] != '^') && (lscreen[nyr][x] != ' ') &&
  155.     (lscreen[nyr][x] != 'M') && (lscreen[nyr][x] != 'B'))
  156.     nyr = -1;
  157.     if ((lscreen[y][x+1] == '<') &&
  158.     (nyr>=0)&&(x+1<ROWLEN)) {    /* arrow moves ( < ) ? */
  159.     moving = 1;
  160.     lscreen[y][x+1] = ' ';
  161.     if (lscreen[nyr][x] == '@') {
  162.         strcpy(howdead,"a speeding arrow");
  163.             if(audio_flag) play_audio_sample(KILLED_BY_A_SND);
  164.         retval = 1;
  165.     }
  166.     if (lscreen[nyr][x] == 'M') {
  167.         *mx = *my = -2;
  168.         lscreen[nyr][x] = ' ';
  169.             if(audio_flag) play_audio_sample(DEAD_M_SND);
  170.     }
  171.     if (lscreen[nyr][x] == 'B') {
  172.         retval = bang(x,nyr,mx,my,sx,sy,howdead);
  173.         return retval;
  174.     }
  175.     lscreen[nyr][x] = '<';
  176.     draw_object(y,x+1,' ');
  177.     draw_object(nyr,x,'<');
  178.         if(audio_flag) play_audio_sample(MOVING_ARROW_SND);
  179.         refresh_screen();
  180.     delay(pause1);
  181.     retval += fall(mx,my,x-1,nyr,sx,sy,howdead);
  182.     moving = 0;
  183.     retval += check(mx,my,x+1,y,-1,0,sx,sy,howdead);
  184.     if (lscreen[nyr][x-1] == '@') {
  185.         strcpy(howdead,"a speeding arrow");
  186.             if(audio_flag) play_audio_sample(KILLED_BY_A_SND);
  187.         return(1);
  188.     }
  189.     if (lscreen[nyr][x-1] == 'M') {
  190.         *mx = *my = -2;
  191.         lscreen[nyr][x-1] = ' ';
  192.             if(audio_flag) play_audio_sample(DEAD_M_SND);
  193.     }
  194.     }
  195.     if ((lscreen[nyl][x] != ' ') && (lscreen[nyl][x] != '^') &&
  196.     (lscreen[nyl][x] != 'M') && (lscreen[nyl][x] != 'B'))
  197.     nyl = -1;
  198.     if ((lscreen[y][x-1] == '>') && (nyl >= 0) &&
  199.     (x > 0)) {    /* arrow moves ( > ) ? */
  200.     moving = 1;
  201.     lscreen[y][x-1] = ' ';
  202.     if (lscreen[nyl][x] == '@') {
  203.         strcpy(howdead,"a speeding arrow");
  204.             if(audio_flag) play_audio_sample(KILLED_BY_A_SND);
  205.         retval = 1;
  206.         }
  207.     if (lscreen[nyl][x] == 'M') {
  208.         *mx = *my = -2;
  209.         lscreen[nyl][x] = ' ';
  210.             if(audio_flag) play_audio_sample(DEAD_M_SND);
  211.         }
  212.     if (lscreen[nyr][x] == 'B') {
  213.         retval = bang(x,nyr,mx,my,sx,sy,howdead);
  214.         return retval;
  215.     }
  216.     lscreen[nyl][x] = '>';
  217.         draw_object(y,x-1,' ');
  218.     draw_object(nyl,x,'>');
  219.         if(audio_flag) play_audio_sample(MOVING_ARROW_SND);
  220.         refresh_screen();
  221.     delay(pause1);
  222.     retval += fall(mx,my,x+1,nyl,sx,sy,howdead);
  223.     moving = 0;
  224.     retval += check(mx,my,x-1,y,1,0,sx,sy,howdead);
  225.     if (lscreen[nyl][x+1] == '@') {
  226.         strcpy(howdead,"a speeding arrow");
  227.             if(audio_flag) play_audio_sample(KILLED_BY_A_SND);
  228.         return(1);
  229.     }
  230.     if (lscreen[nyl][x+1] == 'M') {
  231.         *mx = *my = -2;
  232.         lscreen[nyl][x+1] = ' ';
  233.             if(audio_flag) play_audio_sample(DEAD_M_SND);
  234.     }
  235.     }
  236.  
  237.     if (lscreen[y][nxu] != ' ')
  238.     nxu = -1;
  239.     if ((lscreen[y+1][x] == '^') && (nxu >= 0) && (y < NOOFROWS) &&
  240.     (lscreen[y][x] != '^')&&(lscreen[y][x] != 'B')) {    /* balloon rises? */
  241.     lscreen[y+1][x] = ' ';
  242.     lscreen[y][nxu] = '^';
  243.     draw_object(y+1,x,' ');
  244.     draw_object(y,nxu,'^');
  245.         refresh_screen();
  246.     delay(pause1);
  247.     retval += fall(mx,my,nxu ,y-1,sx,sy,howdead);
  248.     retval += check(mx,my,x,y+1,0,-1,sx,sy,howdead);
  249.     }
  250.  
  251.     nx = x; ny = y;
  252.  
  253.     if (lscreen[y][x] == ' ') {     /* thingy moves? */
  254.     if ((y > 1) && (lscreen[y-1][x] == '~') && (lscreen[y-2][x] == 'O'))
  255.         /* boulder pushes */
  256.         ny--;
  257.     else if ((x > 1) && (lscreen[y][x-1] == '~') && (lscreen[y][x-2] == '>'))
  258.         /* arrow pushes */
  259.         nx--;
  260.     else if ((x < (ROWLEN-1)) && (lscreen[y][x+1] == '~') &&
  261.         (lscreen[y][x+2] == '<'))
  262.         /* arrow pushes */
  263.         nx++;
  264.     else if ((y < (NOOFROWS-1)) && (lscreen[y+1][x] == '~') &&
  265.         (lscreen[y+2][x] == '^'))
  266.          /* balloon pushes */
  267.         ny++;
  268.     }
  269.  
  270.     if ((x != nx) || (y != ny)) {
  271.     lscreen[y][x] = '~';
  272.     lscreen[ny][nx] = lscreen[2*ny-y][2*nx-x];
  273.     lscreen[2*ny-y][2*nx-x] = ' ';
  274.         draw_object(ny*2-y,nx*2-x,' ');
  275.     draw_object(ny,nx,lscreen[ny][nx]);
  276.     draw_object(y,x,'~');
  277.         refresh_screen();
  278.     delay(pause1);
  279.     retval += fall(mx,my,2*x-nx,2*y-ny,sx,sy,howdead);
  280.     retval += check(mx,my,2*nx-x,2*ny-y,nx-x,ny-y,sx,sy,howdead);
  281.     }
  282.  
  283.     if (retval > 0)
  284.     return(1);
  285.     return(0);
  286. }
  287.  
  288. int bang(x, y, mx, my, sx, sy, howdead)    
  289. /* explosion centre x,y */
  290. int x, y, sx, sy, *mx, *my;
  291. char *howdead;
  292. {
  293.     int retval = 0;
  294.     int ba, bb;    /* abbrevs for 'bang index a' and 'bang index b' :-) */
  295.     int gottim = 0;
  296.  
  297.     lscreen[y][x] = ' ';
  298. /* fill with bangs */
  299.     for (ba = -1; ba < 2; ba++)
  300.     for (bb = -1; bb < 2; bb++) {
  301.         if (lscreen[y+ba][x+bb] == '#') continue; /* rock indestructable */
  302.         if (lscreen[y+ba][x+bb] == '@') gottim = 1;
  303.         if (lscreen[y+ba][x+bb] == 'M') *mx = *my = -2; /* kill monster */
  304.         if (lscreen[y+ba][x+bb] == 'B')
  305.         gottim += bang(x+bb,y+ba,mx,my,sx,sy,howdead);
  306.         lscreen[y+ba][x+bb] = ' ';
  307.  
  308.         if (((x+bb) > -1) && ((y+ba) > -1) &&
  309.             ((x+bb) < ROWLEN) && ((y+ba) < NOOFROWS)) {
  310.               draw_object(y+ba,x+bb,'%');
  311.                   }
  312.     }
  313.     refresh_screen();
  314.     if (gottim) {
  315.     strcpy(howdead,"an exploding bomb");
  316.     return 1;
  317.     }
  318. /* erase it all */
  319.     for (ba = -1; ba < 2; ba++)
  320.     for (bb = -1; bb < 2; bb++) {
  321.         if (lscreen[y+ba][x+bb] == '#') continue;
  322.         if (((x+bb) > -1) && ((y+ba) > -1) &&
  323.         ((x+bb) < ROWLEN) && ((y+ba) < NOOFROWS)) {
  324.          draw_object(y+ba,x+bb,' ');
  325.         }
  326.     }
  327.      refresh_screen();
  328.  
  329. /* make all the necessary falling */
  330.     retval = check(mx,my,x-1,y-1,1,0,sx,sy,howdead);
  331.     retval += check(mx,my,x-1,y+1,0,-1,sx,sy,howdead);
  332.     retval += check(mx,my,x+1,y-1,0,1,sx,sy,howdead);
  333.     retval += check(mx,my,x+1,y+1,-1,0,sx,sy,howdead);
  334.     return retval;
  335. }
  336.